package com.xaicode.learn.util.timer;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @author Locker xaicode@sina.com
 * @version 1.0
 * @date 2021/6/12 0012 23:41
 */
public class TimerUtil {

    public static final Integer ZERO = 0;
    public static final Integer MILL_100 = 100;
    public static final Integer MILL_500 = 500;
    public static final Integer SEC_1 = 1000;
    public static final Integer SEC_10 = SEC_1 * 10;
    public static final Integer MIN_1 = SEC_1 * 60;
    public static final Integer MIN_10 = MIN_1 * 10;

    /**
     * create timer task
     *
     * @param timerTask task to be scheduled.
     * @param delay     delay in milliseconds before task is to be executed.
     * @param period    time in milliseconds between successive task executions.
     */
    public static void run(TimerTask timerTask, Integer delay, Integer period) {
        Timer timer = new Timer();
        timer.schedule(timerTask, delay, period);
    }

    public static void run(TimerTask timerTask) {
        run(timerTask, 0, 0);
    }

    public static void run(TimerTask timerTask, Integer delay) {
        run(timerTask, delay, 0);
    }

}
